import os
import shutil
import tqdm

#设定文件夹路径
labels_dir = '/files/data/view_of_delft_PUBLIC/__delft/samples/label_txt'

lidar_src = '/files/data/view_of_delft_PUBLIC/lidar/training/velodyne'
lidar_dst = '/files/data/view_of_delft_PUBLIC/__delft/lidar_bin'
radar_src = '/files/data/view_of_delft_PUBLIC/radar/training/velodyne'
radar_dst = '/files/data/view_of_delft_PUBLIC/__delft/radar_bin'
image_src = '/files/data/view_of_delft_PUBLIC/lidar/training/image_2'
image_dst = '/files/data/view_of_delft_PUBLIC/__delft/camera/camera75'

src_dirs = []
src_dirs.append(lidar_src)
src_dirs.append(radar_src)
src_dirs.append(image_src)

dst_dirs = []
dst_dirs.append(lidar_dst)
dst_dirs.append(radar_dst)
dst_dirs.append(image_dst)

# 遍历label文件夹中的所有txt文件
for filename in tqdm.tqdm(os.listdir(labels_dir)):
    if filename.endswith('.txt'):
        # 提取txt文件名（不含扩展名），假设它与bin文件同名
        base_name = os.path.splitext(filename)[0]

        for src, dst in zip(src_dirs,dst_dirs):
            bin_file_path = os.path.join(src, f"{base_name}.bin")
            jpg_file_path = os.path.join(src, f"{base_name}.jpg")

            if not (os.path.exists(bin_file_path) or os.path.exists(jpg_file_path)):
                print(f"No .bin file found for {filename}")

            # 检查bin文件是否存在
            if os.path.exists(bin_file_path):
                # 拷贝bin文件到lidar2文件夹
                shutil.copy(bin_file_path, os.path.join(dst, f"{base_name}.bin"))

            if os.path.exists(jpg_file_path):
                # 拷贝bin文件到lidar2文件夹
                shutil.copy(jpg_file_path, os.path.join(dst, f"{base_name}.jpg"))

print("Finished copying files.")